import { applyMiddleware, configureStore, Tuple } from "@reduxjs/toolkit";
import { deviceReducer } from "./deviceSlice";
import { songReducer } from "./songSlice";
import { socketReducer } from "./socketSlice";
import { timerReducer } from "./timerSlice";
import { thunk } from "redux-thunk";
import { collectionReducer } from "./collectionSlice";
import { memoReducer } from "./MemoSlice";
import { clipboardReducer } from "./clipboardSlice";
import { collectionTypeReducer } from "./collectionTypeSlice";
import { uploadReducer } from "./uploadSlice";

export const store = configureStore({
  reducer: {
    device: deviceReducer,
    song: songReducer,
    socket: socketReducer,
    timer: timerReducer,
    collection: collectionReducer,
    collectionType: collectionTypeReducer,
    memo: memoReducer,
    clipboard: clipboardReducer,
    upload: uploadReducer,
  },
  middleware: (getDefaultMiddleware) => {
    const defaultMiddlewares = getDefaultMiddleware();
    return defaultMiddlewares.concat(thunk);
  },
});

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>;
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch;
